package org.javaongems.user.gwthandler;

import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;

import com.google.gwt.user.client.rpc.RemoteService;

final public class Utils {
	final static public Class[] SET_THREAD_LOCAL_HTTP_SERVLET_REQUEST_PARAMS = { HttpServletRequest.class };
	final static public String SET_THREAD_LOCAL_HTTP_SERVLET_REQUEST_METH = "setThreadLocalHttpServletRequest";

	private Utils() {
	}

	static public Method querySetThreadLocalHttpServletRequestMethod(
			RemoteService rpcImpl) {
		Class implClass = rpcImpl.getClass();
		return querySetThreadLocalHttpServletRequestMethod(implClass);
	}

	static public Method querySetThreadLocalHttpServletRequestMethod(
			Class implClass) {
		Method ret = null;
		try {
			ret = implClass.getDeclaredMethod(
					SET_THREAD_LOCAL_HTTP_SERVLET_REQUEST_METH,
					SET_THREAD_LOCAL_HTTP_SERVLET_REQUEST_PARAMS);
		} catch (NoSuchMethodException err) {
			// its ok, not all rpc impls will declare one
		}
		return ret;
	}
}
